package com.zmcc.service.impl;

import com.google.gson.Gson;
import com.zmcc.entity.CallTipsCorpUserInfoTemplate;
import com.zmcc.entity.CallTipsSettingTemplate;
import com.zmcc.entity.EnMmsReleaseTemplate;
import com.zmcc.entity.common.CommonRequest;
import com.zmcc.service.ICallTipsRequest;

import java.util.HashMap;
import java.util.Map;

public class EnMmsCommercial implements ICallTipsRequest{
    private final static String url = "https://dev.cmccopen.cn/api";

    private static EnMmsCommercial enMmsCommercial;

    public static synchronized EnMmsCommercial getInstance() {
        if (enMmsCommercial == null) {
            enMmsCommercial = new EnMmsCommercial();
        }
        return enMmsCommercial;
    }

    @Override
    public CommonRequest getUpdateCorpUserInfoRequest(CallTipsCorpUserInfoTemplate template) {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1" + "/emms" + "/updateCorpUserInfo");
        request.setBody(new Gson().toJson(template));
        return request;
    }

    @Override
    public CommonRequest getAddTemplateRequest(String subtitle, String templateContent) {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1" + "/emms" + "/template" + "/add");
        Map<String, String> bodyMap = new HashMap<>();
        bodyMap.put("subtitle", subtitle);
        bodyMap.put("templateContent", templateContent);
        request.setBody(new Gson().toJson(bodyMap));
        return request;
    }

    @Override
    public CommonRequest getUpdateTemplateRequest(String templateID, String templateContent) {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1" + "/emms" + "/template" + "/update");
        Map<String, String> bodyMap = new HashMap<>();
        bodyMap.put("templateID", templateID);
        bodyMap.put("templateContent", templateContent);
        request.setBody(new Gson().toJson(bodyMap));
        return request;
    }

    @Override
    public CommonRequest getQueryTemplateRequest(String beginDate, String endDate) {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1" + "/emms" + "/template" + "/query");
        Map<String, String> bodyMap = new HashMap<>();
        bodyMap.put("beginDate", beginDate);
        bodyMap.put("endDate", endDate);
        request.setBody(new Gson().toJson(bodyMap));
        return request;
    }

    @Override
    public CommonRequest getDelTemplateRequest(String templateID) {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1" + "/emms" + "/template" + "/del");
        Map<String, String> bodyMap = new HashMap<>();
        bodyMap.put("templateID", templateID);
        request.setBody(new Gson().toJson(bodyMap));
        return request;
    }

    @Override
    public CommonRequest getAddSettingRequest(CallTipsSettingTemplate template) {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1" + "/emms"  + "/setting" +"/add");
        request.setBody(new Gson().toJson(template));
        return request;
    }

    @Override
    public CommonRequest getQuerySettingRequest(String beginTime, String endTime, String[] phoneNumberList) {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1" + "/emms" + "/template" + "/setting" +"/list");
        Map<String, Object> bodyMap = new HashMap<>();
        bodyMap.put("beginTime", beginTime);
        bodyMap.put("endTime", endTime);
        bodyMap.put("phoneNumberList", phoneNumberList);
        request.setBody(new Gson().toJson(bodyMap));
        return request;
    }

    @Override
    public CommonRequest getSettingDetailRequest(String ruleId) {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1" + "/emms" + "/setting" +"/detail");
        Map<String, Object> bodyMap = new HashMap<>();
        bodyMap.put("ruleId", ruleId);
        request.setBody(new Gson().toJson(bodyMap));
        return request;
    }


    @Override
    public CommonRequest getDelSettingRequest(String ruleId, String[] phoneNumberList) {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1" + "/emms" + "/setting" +"/del");
        Map<String, Object> bodyMap = new HashMap<>();
        bodyMap.put("ruleId", ruleId);
        bodyMap.put("phoneNumberList", phoneNumberList);
        request.setBody(new Gson().toJson(bodyMap));
        return request;
    }

    @Override
    public CommonRequest getReleaseRequest(EnMmsReleaseTemplate template) {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1" + "/emms" + "/attachment" + "/release");
        request.setBody(new Gson().toJson(template));
        return request;
    }

    @Override
    public CommonRequest getUploadRequest() {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1" + "/emms" + "/attachment" + "/upload");
        return request;
    }
}
